//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Widgets_Common.txt
// Include File to hold all Common Variables and Subroutines
// Version 3.0 - 09/12/01 - Incorporated Digit_Widgets_Animation Script 
// Added recall of position mark Material, Color and Tool if the user isn't holding an object in transform
//	Version 3.1 - 09/15/01 - Updated with Advanced and Standard Animation Scripts
//***************************************************
//Document stuff
[VarSet,docWidth,DOCUMENT:MODIFIERS:WIDTH]
[VarSet,docHeight,DOCUMENT:MODIFIERS:HEIGHT]
[VarSet,docMidX,docWidth/2]
[VarSet,docMidY,docHeight/2]
//Widget's Stuff
[varDef,ICurrX,0]
[varDef,ICurrY,0]
[varDef,ICurrZ,0]
[varDef,ICurrXS,0]
[varDef,ICurrYS,0]
[varDef,ICurrZS,0]
[varDef,CurrXR,0]
[varDef,CurrYR,0]
[varDef,CurrZR,0]
//****************************
// Position Marker Definitions
//****************************
[VarDef,SpointX(2),0]
[VarDef,SpointY(2),0]
[VarDef,SpointZ(2),0]
[VarDef,SpointXS(2),10]
[VarDef,SpointYS(2),10]
[VarDef,SpointZS(2),10]
[VarDef,SpointXR(2),0]
[VarDef,SpointYR(2),0]
[VarDef,SpointZR(2),0]
//****************************
//Keep Points
//****************************
[VarDef,KpointX(2),0]
[VarDef,KpointY(2),0]
[VarDef,KpointZ(2),0]
[VarDef,KpointXS(2),0]
[VarDef,KpointYS(2),0]
[VarDef,KpointZS(2),0]
[VarDef,KpointXR(2),0]
[VarDef,KpointYR(2),0]
[VarDef,KpointZR(2),0]
[VarDef,sel1,1]
[VarDef,sel2,2]
//****************************
//Position Mark Common
//****************************
[VarDef,maxAvailablemarks,10] 
[VarDef,MarkTool(maxAvailablemarks+1),0]
[VarDef,MarkMat(maxAvailablemarks+1),0]
[VarDef,MarkR(maxAvailablemarks+1),0]
[VarDef,MarkG(maxAvailablemarks+1),0]
[VarDef,MarkB(maxAvailablemarks+1),0]
[varDef,MarkX(maxAvailablemarks+1)]  
[varDef,MarkY(maxAvailablemarks+1)]  
[varDef,MarkZ(maxAvailablemarks+1)]  
[varDef,MarkXS(maxAvailablemarks+1)]  
[varDef,MarkYS(maxAvailablemarks+1)]  
[varDef,MarkZS(maxAvailablemarks+1)]  
[varDef,MarkXR(maxAvailablemarks+1)]  
[varDef,MarkYR(maxAvailablemarks+1)]  
[varDef,MarkZR(maxAvailablemarks+1)]  
[varDef,MarkIndex,1]
//****************************
//Angle Common
//****************************
[VarDef,dangle,0]
[VarDef,dangle1,0]
[VarDef,zdangle,0]
[VarDef,zdangle1,0]
[VarDef,ZRead,0]
[VarDef,Gxyangle,0]
[VarDef,Gxzangle,0]
//[PenMove,0,2][Title,"      A Digit Widget      "]
//[Image,Widgetsbanner.psd,0]
//****************************
//Pointer Common
//****************************
[VarDef,curmX]
[VarDef,curmY]
[VarDef,curmZ]
[VarDef,Xangle,0]
[VarDef,Yangle,0]
[VarDef,kx,0]
[VarDef,ky,0]
[VarDef,kz,0]
[VarDef,pkx,0]
[VarDef,pky,0]
[VarDef,pkz,0]
//****************************
//moveto common
//****************************
[VarDef,sel1,1]
[VarDef,sel2,2]
[VarDef,middlex,0]
[VarDef,middley,0]
[VarDef,middlez,0]
//****************************
//mousecommon
//****************************
[varDef,Hval1,320]
[varDef,Vval1,258]
[varDef,Hval2,320]
[varDef,Vval2,258]
[varDef,Zval1,0]
[varDef,Zval2,0]
[varDef,Ldiam,10]
//****************************
//pixol information common
//****************************
[VarDef,theStroke,0]
[VarDef,GetColors,0]
[VarDef,GetDepthandMat,1]
[VarDef,GetNorms,2]
[VarDef,CenterColor,0]
[VarDef,CColor,0]
[VarDef,Rcolor,0]
[VarDef,Gcolor,0]
[VarDef,Bcolor,0]
[VarDef,Pmat,0]
[VarDef,Normx,0]
[VarDef,Normy,0]
[VarDef,Normz,0]
[VarDef,dummy,0]
[VarDef,Aptr,0]
//**********************
//ColorWidget Definitions
//**********************
[VarDef,CRadius,50]
[VarDef,Sred(10)]
[VarDef,Sgreen(10)]
[VarDef,Sblue(10)]
[VarDef,rincrm,1]
[VarDef,gincrm,1]
[VarDef,bincrm,1]
[VarDef,colcntr,0]
[VarDef,XYcolorDepth,500]
[VarDef,ZcolorDepth,500]
[VarDef,XcolorCenter,0]
[VarDef,YcolorCenter,0]
[VarDef,ZcolorCenter,0]
[VarDef,cxmode,0]
[VarDef,cymode,0]
[VarDef,czmode,1]
[VarDef,deltr,0]
[VarDef,deltg,0]
[VarDef,deltb,0]
[VarDef,Samps(255)]
[VarDef,Sptr,0]
[VarDef,hDelta,0]
[VarDef,vDelta,0]
[VarDef,hcnt,0]
[VarDef,vcnt,0]
[VarDef,ccolor,0]
[VarDef,chk,0]
[VarDef,found,0]
[VarDef,Sampend,0]
[VarDef,PHval1,0]
[VarDef,PHval2,0]
[VarDef,PVval1,0]
[VarDef,PVval2,0]
[VarDef,PZVal,0]
[VarDef,pensize,0]
[VarDef,vsizer,0]
[VarDef,hsizer,0]
[VarDef,maxZdelta,500]
[FontSetSizeMedium][FontSetColor,255,255,255]
[FontSetColor,255,200,0]**************** Digit's Widgets ****************[FontSetColor,160,160,160]
[pd][FontSetSizeSmall][FontSetColor,255,255,255]
[PD]
//***************************************************
// Widget_Layer Include File
// Layer Manipulation Script
//***************************************************
[varDef,Lvmove,0]
[varDef,Lhmove,0]
[varDef,Lzmove,0]
[FontSetColor,255,200,0]Layer Control...[FontSetColor,160,160,160]
//**************************************************************************
//********************Layer Control ****************************************
//**************************************************************************
[iSlider,"LayerH  ",0,1,-DocWidth,DocWidth,"Layer Horiz", 	[varSet,Lhmove,zscript:LayerH],0,[TextCalcWidth,MaxZdepth123456]]
[iSlider,"LayerV  ",0,1,-DocWidth,DocWidth,"Layer Vert",	[varSet,Lvmove,zscript:LayerV],0,[TextCalcWidth,MaxZdepth123456]]
[iSlider,"LayerZ  ",0,1,-5000,5000,"Layer Zdepth",		[varSet,Lzmove,zscript:LayerZ],0,[TextCalcWidth,MaxZdepth123456]]

[iButton," LayerMove ","Move Layer Coords",
	[Iset, Layer:Modifiers:DisplaceH,Lhmove]
	[ISet, Layer:Modifiers:DisplaceV,Lvmove]
	[ISet, Layer:Modifiers:DisplaceZ,Lzmove]
] //end of LayerMove
[PD]
//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Widget_Zdepth 
// Calculate Size according to ZDepth Area and ZReference  
//********************************************************
[FontSetColor,255,200,0]ZDepth Area Size[FontSetColor,160,160,160]
//Automatically set size of object according to depth. Size drawn will become size determined from Reference point
//Set defaults so that user doesn't get an error if he forgets to set it
[VarDef,ZArea,500]
[VarDef,RefX,DocMidX]
[VarDef,RefY,DocMidY]
[VarDef,RefZ,0]
[VarDef,RefXS,20]
[VarDef,RefYS,20]
[VarDef,RefZS,20]
[VarDef,RefMult,.5]
[VarDef,Zfactor,0]
[VarDef,ZDmult,1]
[iSlider,"MaxZdepth   ",500,.1,0,4000,"Zdepth Cube Setting",[varSet,ZArea,zscript:MaxZdepth],0,[TextCalcWidth,MaxZdepth12345678]]
[iSlider,"ZDepthMult  ",1,.1,1,100,"Zdepth Muliplier Setting",[varSet,ZDmult,zscript:ZDepthMult],0,[TextCalcWidth,MaxZdepth12345678]]
[iButton," RefObject ","Grab Reference according to MaxZDepth",
	[TransformGet,RefX,RefY,RefZ,RefXS,RefYS,RefZS]
	[VarSet,Zfactor,ZArea-RefZ]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,RefMult,Zfactor/TotalArea]
]
[iButton," SizeObject ","Size Object according to MaxZDepth",
	//go ahead and get all of the current data 
	[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
	[RoutineCall,DepthCalc]
]//end SizeObject
//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Widget_NosePointer by Davey
// Point Nose of 3D object to any point in space
// Origin Point entered here will be used by other functions  
//********************************************************

[PD]
[FontSetColor,255,200,0]Nose Pointer[FontSetColor,160,160,160]

[iSlider,"X Center",docWidth/2,.1,-4096,4096,"X Component",,,120]
[iSlider,"Y Center",docHeight/2,.1,-4096,4096,"Y Component",,,120]
[iSlider,"Z Center",0,.1,-4096,4096,"Z Component",,,120]
[iButton,"Use Current","Put current object's position into these sliders",
	[transformGet,curmX,curmY,curmZ]
	[iSet,zscript:xcenter,curmX]
	[iSet,zscript:ycenter,curmY]
	[iSet,zscript:zcenter,curmZ]
,,] // end iButton

[iButton,"Point","Point current 3D object toward the center indicated above",
	[if,[isDisabled,transform:move],
		[messageOK,"Most recently-drawn item must be a 3D object in a Transform or Edit mode"]
	, // else
	[transformGet,ICurrX,ICurrY,ICurrZ,ICurrXS,ICurrYS,ICurrZS,CurrXR,CurrYR,CurrZR]
	[varSet,curmX,[iGet,zscript:xcenter]]
	[varSet,curmY,[iGet,zscript:ycenter]]
	[varSet,curmZ,[iGet,zscript:zcenter]]
	[routineCall,PointFromTo,ICurrX,ICurrY,ICurrZ,curmX,curmY,curmZ,Xangle,Yangle]
	[transformSet,,,,,,,Xangle,Yangle,CurrZR]
	]
,,] // end iButton

//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Random Object Placer
// Enter Radius of Random Space
//********************************************************

[PD]
[FontSetColor,255,200,0]3D Random [FontSetColor,160,160,160]
[VarDef,RRadius,100]
[VarDef,hradius,0]
[VarDef,vradius,0]
[VarDef,zradius,0]
[iSlider,"RandomRange  ",100,1,1,4000,"Diameter Range from Origin",[varSet,RRadius,zscript:RandomRange],0,[TextCalcWidth,XYAngle12345]]
[IButton,"Randomize a Object","Make Random the current object",
	[varSet,zradius,rand(RRadius)]
	[varSet,vradius,rand(RRadius)]
	[varSet,hradius,rand(RRadius)]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,zradius,zradius*-1]
	]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,vradius,vradius*-1]
	]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,hradius,hradius*-1]
	]
	
	[TransformGet,IcurrX,IcurrY,IcurrZ]
	[transformSet,IcurrX + hradius,IcurrY + vradius,IcurrZ + zradius]

]
[VarDef,Clicked,0]
[VarDef,Zdopick,0]
[IButton,"Pick Randomize a Object","Make Random Depth the current selection by mouseclick",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	//figure out the line here now that we have the Z values and positions	
	//place current selection on canvas and go to edit
	[canvasClick,320,258,320,264]
	[iPress,transform:Move]
	//Do the line
	//make scaling right
	[VarSet,Zdopick,rand(ZArea)]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,Zdopick,Zdopick*-1]
	]
	[Note,zradius,,1]
	[TransformSet,Hval1,Vval1,Zdopick,Ldiam,Ldiam,Ldiam]
]
//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Color Widget Control
//********************************************************
[PD]
[FontSetColor,255,200,0]Color Gradient Utility[FontSetColor,160,160,160]
[PD]
//Must reset everything when something changes
[iSlider,"ColorStep  ",50,1,1,255,"Gradient Resolution",
	[varSet,CRadius,zscript:ColorStep]
	[VarSet,rincrm,(Sred(1)-Sred(0))/Cradius]
	[VarSet,gincrm,(Sgreen(1)-Sgreen(0))/Cradius]
	[VarSet,bincrm,(Sblue(1)-Sblue(0))/Cradius]
	[if,rincrm=0,[VarSet,rincrm,.00001]]
	[if,gincrm=0,[VarSet,gincrm,.00001]]
	[if,bincrm=0,[VarSet,bincrm,.00001]]
	[VarSet,Rcolor,Sred(0)]
	[VarSet,Gcolor,Sgreen(0)]
	[VarSet,Bcolor,Sblue(0)]
,0,[TextCalcWidth,XYAngle1234567890]]
[iSlider,"ColorXYDepth  ",500,1,-4000,4000,"Set Color XYdepth Maximum",[VarSet,xycolorDepth,zscript:ColorXYDepth],0,[TextCalcWidth,XYAngle1234567890]]
[iSlider,"ColorZDepth  ",500,1,-4000,4000,"Set Color Zdepth Maximum",[VarSet,ZcolorDepth,zscript:ColorZDepth],0,[TextCalcWidth,XYAngle1234567890]]
[ibutton,"3DColor","Color Current Object with 3DColor",
	[transformget,kx,ky,kz]			//what Z do we be?
	[RoutineCall,ZcolorCalc,kx,ky,kz]
]
[IButton,"ColorPick ","Pick a color based on XYZ Pixol on Canvas",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	[RoutineCall,PixolLook,Hval1,Vval1,1,Zval1,dummy,dummy,dummy]
	[RoutineCall,ZcolorCalc,Hval1,Vval1,Zval1]
]
[PD]
//determine what axis to use, you can use more than one
[iSwitch,"C-X",1,"X calc",]
[iSwitch,"C-Y",1,"Y calc",]
[iSwitch,"C-Z",1,"Z calc",]

[iSlider,"XColorCtr ",0,1,-4000,4000,"Current X Center",[VarSet,XcolorCenter,zscript:XColorCtr],0,[TextCalcWidth,XYAngle1234567890]]
[iSlider,"YColorCtr ",0,1,-4000,4000,"Current Y Center",[VarSet,YcolorCenter,zscript:YColorCtr],0,[TextCalcWidth,XYAngle1234567890]]
[iSlider,"ZColorCtr ",0,1,-4000,4000,"Current Z Center",[VarSet,ZcolorCenter,zscript:ZColorCtr],0,[TextCalcWidth,XYAngle1234567890]]
[ibutton,"Set-Center","Set Center for ZColor",
	[transformget,XcolorCenter,YcolorCenter,ZcolorCenter]			//what Z do we be?
	[Iset,zscript:XcolorCtr,XcolorCenter]
	[Iset,zscript:YcolorCtr,YcolorCenter]
	[Iset,zscript:ZcolorCtr,ZcolorCenter]
]
[IButton,"PickCenter ","Pick the Center based on XYZ Pixol on Canvas",
	[RoutineCall,Mouselook,XcolorCenter,YcolorCenter,Hval2,Vval2,Clicked]
	[RoutineCall,PixolLook,XcolorCenter,YcolorCenter,1,ZcolorCenter,dummy,dummy,dummy]
	[Iset,zscript:XcolorCtr,XcolorCenter]
	[Iset,zscript:YcolorCtr,YcolorCenter]
	[Iset,zscript:ZcolorCtr,ZcolorCenter]
	[Note,"You May Have to Set Z Manually",,1]
]
[PD]
[iSlider,"Red1  ",0,1,1,255,"Selected Start Red",
	[varSet,Sred(0),zscript:Red1]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[iSlider,"Green1",0,1,1,255,"Selected Start Green",
	[varSet,Sgreen(0),zscript:Green1]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[iSlider,"Blue1 ",0,1,1,255,"Selected Start Blue",
	[varSet,Sblue(0),zscript:Blue1]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[ibutton,"StartColor","Pick Starting Color",
	[VarSet,Sred(0),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(0),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(0),[IGet,Color:Bluecomponent]]
	//Init color
	[RoutineCall,initcolor]
	[Iset,zscript:Red1,Sred(0)]
	[Iset,zscript:Green1,Sgreen(0)]
	[Iset,zscript:Blue1,Sblue(0)]
	[Iset,zscript:Red2,Sred(1)]
	[Iset,zscript:Green2,Sgreen(1)]
	[Iset,zscript:Blue2,Sblue(1)]
]
[PD]
[iSlider,"Red2  ",255,1,1,255,"Selected End Red",
	[varSet,Sred(1),zscript:Red2]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[iSlider,"Green2",255,1,1,255,"Selected End Green",
	[varSet,Sgreen(1),zscript:Green2]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[iSlider,"Blue2 ",255,1,1,255,"Selected End Blue",
	[varSet,Sblue(1),zscript:Blue2]
	[RoutineCall,initcolor]
,0,[TextCalcWidth,XYAngle12345]]
[ibutton,"EndColor","Pick Ending Color",
	[VarSet,Sred(1),[IGet,Color:Redcomponent]]
	[RoutineCall,initcolor]
	[Iset,zscript:Red1,Sred(0)]
	[Iset,zscript:Green1,Sgreen(0)]
	[Iset,zscript:Blue1,Sblue(0)]
	[Iset,zscript:Red2,Sred(1)]
	[Iset,zscript:Green2,Sgreen(1)]
	[Iset,zscript:Blue2,Sblue(1)]
]
[ibutton,"Swap","Swap Start and Ending Color",
	[VarSet,dummy,SRed(1)]
	[VarSet,Sred(1),Sred(0)]
	[VarSet,Sred(0),dummy]
	[VarSet,dummy,Sgreen(1)]
	[VarSet,Sgreen(1),Sgreen(0)]
	[VarSet,Sgreen(0),dummy]
	[VarSet,dummy,Sblue(1)]
	[VarSet,Sblue(1),Sblue(0)]
	[VarSet,Sblue(0),dummy]
	[RoutineCall,initcolor]
	[Iset,zscript:Red1,Sred(0)]
	[Iset,zscript:Green1,Sgreen(0)]
	[Iset,zscript:Blue1,Sblue(0)]
	[Iset,zscript:Red2,Sred(1)]
	[Iset,zscript:Green2,Sgreen(1)]
	[Iset,zscript:Blue2,Sblue(1)]
]
[PD]
[ibutton,"Vary Color Random","Vary Center Color Randomly",
	[VarSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,kx,Sred(0)+rand(Cradius)]
	,
		[VarSet,kx,Sred(0)-rand(Cradius)]
	]

	[VarSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,ky,Sgreen(0)+rand(Cradius)]
	,
		[VarSet,ky,Sgreen(0)-rand(Cradius)]
	]

	[VarSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,kz,Sblue(0)+rand(Cradius)]
	,
		[VarSet,kz,Sblue(0)-rand(Cradius)]
	]
	[if,kx > 255,[VarSet,kx,kx - 256]]
	[if,ky > 255,[VarSet,ky,ky - 256]]
	[if,kz > 255,[VarSet,kz,kz - 256]]
	[if,kx < 0,[VarSet,kx,kx + 256]]
	[if,ky < 0,[VarSet,ky,ky + 256]]
	[if,kz < 0,[VarSet,kz,kz + 256]]
	[IColorSet,kx,ky,kz]
	[VarSet,Rcolor,Sred(0)]
	[VarSet,Gcolor,Sgreen(0)]
	[VarSet,Bcolor,Sblue(0)]
]
//Pallete Save and Load
[PD]
[ibutton,"L1","Look This Color",	[Note,,zscript:L1,1,[RGB,Sred(3),Sgreen(3),Sblue(3)]]
,0,40]
[ibutton,"L2","Look This Color",	[Note,,zscript:L2,1,[RGB,Sred(4),Sgreen(4),Sblue(4)]]
,0,40]
[ibutton,"L3","Look This Color",	[Note,,zscript:L3,1,[RGB,Sred(5),Sgreen(5),Sblue(5)]]
,0,40]
[ibutton,"L4","Look This Color",	[Note,,zscript:L4,1,[RGB,Sred(6),Sgreen(6),Sblue(6)]]
,0,40]
[ibutton,"L5","Look This Color",	[Note,,zscript:L5,1,[RGB,Sred(7),Sgreen(7),Sblue(7)]]
,0,40]
[PD]
[ibutton,"R1","Recall This Color",	
	[IcolorSet,Sred(3),Sgreen(3),Sblue(3)]
,0,40]
[ibutton,"R2","Recall This Color",	[
	IcolorSet,Sred(4),Sgreen(4),Sblue(4)]
,0,40]
[ibutton,"R3","Recall This Color",	
	[IcolorSet,Sred(5),Sgreen(5),Sblue(5)]
,0,40]
[ibutton,"R4","Recall This Color",	
	[IcolorSet,Sred(6),Sgreen(6),Sblue(6)]
,0,40]
[ibutton,"R5","Recall This Color",	
	[IcolorSet,Sred(7),Sgreen(7),Sblue(7)]
,0,40]
[PD]
[ibutton,"S1","Save Current Color",
	[VarSet,Sred(3),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(3),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(3),[IGet,Color:Bluecomponent]]
	,0,40]
[ibutton,"S2","Save Current Color",
	[VarSet,Sred(4),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(4),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(4),[IGet,Color:Bluecomponent]]
,0,40]
[ibutton,"S3","Save Current Color",
	[VarSet,Sred(5),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(5),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(5),[IGet,Color:Bluecomponent]]
,0,40]
[ibutton,"S4","Save Current Color",
	[VarSet,Sred(6),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(6),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(6),[IGet,Color:Bluecomponent]]
,0,40]
[ibutton,"S5","Save Current Color",
	[VarSet,Sred(7),[IGet,Color:Redcomponent]]
	[VarSet,Sgreen(7),[IGet,Color:Greencomponent]]
	[VarSet,Sblue(7),[IGet,Color:Bluecomponent]]
,0,40]
[PD]
[FontSetColor,255,200,0]Color Stroke Utility[FontSetColor,160,160,160]
[PD]
[iSwitch,"Use Samples",0,"Use Sampled Colors",
	[if,zscript:UseZColor,
		[IToggle,zscript:UseZColor]
	]
	[if,zscript:UseShiftColor,
		[IToggle,zscript:UseShiftColor]
	]
] 
[iSwitch,"Use ZColor",1,"Use Zcolor Function Colors",
	[if,zscript:UseSamples,
		[IToggle,zscript:UseSamples]
	]
	[if,zscript:UseShiftColor,
		[IToggle,zscript:UseShiftColor]
	]
] 
[iSwitch,"Use ShiftColor",0,"Use Shifted Colors",
	[if,zscript:UseZColor,
		[IToggle,zscript:UseZColor]
	]
	[if,zscript:UseSamples,
		[IToggle,zscript:UseSamples]
	]
] 
[iButton,"ShiftAxis","Change RGB Axis for Shifting Color",
	[VarInc,Aptr]
	[if,Aptr=3,[VarSet,Aptr,0]]
	[if,Aptr=0,	[note,"XYZ = RGB",,1]]
	[if,Aptr=1,	[note,"XYZ = GBR",,1]]
	[if,Aptr=2,	[note,"XYZ = BRG",,1]]
]
[iSwitch,"Use SetDepth",0,"Limit Z to value"]
[iSlider,"MxZValue",500,1,0,4000,"Maximum Z Delta ",[VarSet,maxZdelta,zscript:MxZValue],0,[TextCalcWidth,SizeIncr4123]]
[iSlider,"SResolution",0,1,0,128,"Stroke Resolution ",[VarSet,dsizer,zscript:SResolution],0,[TextCalcWidth,SizeIncr4123]]
[iButton," GetBstroke ","Grab the Stroke Data",
	[VarSet,theStroke,[StrokeGetLast]] //get the last drawn stroke
]
[VarDef,cnt,0]
[VarDef,Dsizer,0]
[VarDef,dchk,0]
[VarDef,ddel,0]
[iButton," DoBStrokeColor","Do Stroke With Color",
	[VarSet,numpts,[StrokeGetInfo,theStroke,0]]
	//get xy of origin
	[VarSet,ox,[StrokeGetInfo,theStroke,1,0]]
	[VarSet,oy,[StrokeGetInfo,theStroke,2,0]]
	[VarSet,cnt,0]
	[VarSet,Pixcnt,0]
	[VarSet,sptr,0]
	[VarSet,ddel,0]
	[VarSet,dsizer,[Iget,zscript:Sresolution]]
	[if,zscript:UseSamples,
		[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
		[IColorSet,rcolor,gcolor,bcolor]
		[VarInc,sptr]
	]
	[if,zscript:UseZcolor,
		[RoutineCall,ZcolorCalc,ox,oy,0]
	]
	[if,zscript:UseShiftColor,
		[RoutineCall,PixolLook,ox,oy,1,Zval1,dummy,dummy,dummy]
		[RoutineCall,ShiftColor,ox,oy,Zval1,aptr]
	]
	[CanvasClick,ox,oy,ox,oy]

	[loop,numpts,
		[VarSet,ex,[StrokeGetInfo,theStroke,1,cnt]]
		[VarSet,ey,[StrokeGetInfo,theStroke,2,cnt]]

		[if,Pixcnt>dsizer,
			[VarSet,Pixcnt,0]
			[RoutineCall,PixolLook,ex,ey,1,Zval1,dummy,dummy,dummy]
			[if,zscript:UseSamples,
				[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
				[IColorSet,rcolor,gcolor,bcolor]
				[VarInc,sptr]
				[if,sptr=sampend,[VarSet,sptr,0]]
			]
			[if,zscript:UseZcolor,
				[RoutineCall,ZcolorCalc,ex,ey,Zval1]
			]
			[if,zscript:UseShiftColor,
				[RoutineCall,ShiftColor,ex,ey,Zval1,aptr]
			]
			[if,zscript:UseSetDepth,
				[varSet,dchk,abs(zcolorcenter-zval1)]
				[if,dchk < maxZDelta,
					[CanvasClick,ex,ey,ex,ey]
				,//else
					[VarSet,ddel,1]
				]
			,//else
				[CanvasClick,ex,ey,ex,ey]
			]
			[VarSet,ox,ex]
			[VarSet,oy,ey]
		]
		[VarInc,cnt]
		[VarInc,Pixcnt]
	]
	[if,zscript:UseSetDepth,
		[if,ddel>0,
			[Note,maxZDelta,,-1]
			[Note,"....Depth Achieved",,1]
		]
	]
]
[iSlider,"NumSamples",0,1,0,512,"Number of Sampled Colors ",,0,[TextCalcWidth,SizeIncr4123]]
[iButton," GetSamples","Sample Color with Mouse",
	[VarSet,Sptr,0]
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	[VarSet,hDelta,Hval2-Hval1]
	[VarSet,vDelta,Vval2-Vval1]
	[VarSet,hcnt,Hval1]
	[VarSet,vcnt,Vval1]
	[VarSet,ccolor,0]
	[note,Working,,1]
	
	[loop,vDelta,
		[note,sptr,,1]
		[loop,hDelta,
			[RoutineCall,PixolLook,hcnt,vcnt,0,ccolor,dummy,dummy,dummy]
			[VarSet,chk,0]
			[VarSet,found,0]
			//see if we already have it
			[loop,sptr,
				[if,ccolor=samps(chk),
					[VarSet,found,1]
					[LoopExit]
				]
				[VarInc,chk]
			]
			[if,found=0,
				[VarSet,Samps(sptr),ccolor]
				[VarInc,sptr]
			]
			[if,sptr>=255,[LoopExit]]
			[VarInc,hcnt]
		]
		[if,sptr>=255,[LoopExit]]
		[VarSet,hcnt,Hval1]
		[VarInc,vcnt]
	]
	[VarSet,sampend,sptr]
	[note,Done,,1]
	[ISet,zscript:NumSamples,sptr]
]
[PD]
[VarDef,mskR,0]
[VarDef,mskG,0]
[VarDef,mskB,0]
[VarDef,mskcolor,0]
[VarDef,chkcolor,0]
[iSwitch,"PixolColor",0,"Build up Colors"]
[iSwitch,"Use Mask",0,"Build up only Masked Color"]
[iButton,"Get Mask","Grab Mask Color",
	[VarSet,mskR,[IGet,Color:Redcomponent]]
	[VarSet,mskG,[IGet,Color:Greencomponent]]
	[VarSet,mskB,[IGet,Color:Bluecomponent]]
	[VarSet,mskcolor,[RGB,mskR,mskG,mskB]]
]
[iSwitch,"Use Drag",0,"Use Drag Stroke"]
[iButton," PixolPaint","Color 1 Pixol width with Mouse",
	[VarSet,Sptr,0]
	[RoutineCall,Mouselook,PHval1,PVval1,PHval2,PVval2,Clicked]
	[VarSet,hDelta,PHval2-PHval1]
	[VarSet,vDelta,PVval2-PVval1]
	[VarSet,hcnt,PHval1]
	[VarSet,vcnt,PVval1]
	[VarSet,ccolor,0]
	[VarSet,sptr,0]
	[VarSet,pensize,[Iget,Draw:DrawSize]]
	[VarSet,vsizer,INT(vdelta/pensize)+1]
	[VarSet,hsizer,INT(hdelta/pensize)+1]
	[VarSet,pensize,pensize*2]
	[VarSet,ddel,0]

	[if,zscript:usedrag,
		//Find Center
		[VarSet,vsizer,INT(vdelta/2)]
		[VarSet,hsizer,INT(hdelta/2)]
		[RoutineCall,PixolLook,hsizer,vsizer,1,PZval,dummy,dummy,dummy]
		[if,zscript:PixolColor,
			[RoutineCall,PixolLook,hsizer,vsizer,0,chkcolor,rcolor,gcolor,bcolor]
			[if,zscript:usemask,
				[VarSet,tmp,abs(mskcolor-chkcolor)]
				[if,tmp < 1000,
					[IColorSet,rcolor,gcolor,bcolor]
				]
			,//else
				[IColorSet,rcolor,gcolor,bcolor]
			]
		,//else
			[if,zscript:UseZcolor,
				[RoutineCall,ZcolorCalc,hsizer,vsizer,PZval]
			]
			[if,zscript:UseShiftColor,
				[RoutineCall,Shiftcolor,hsizer,vsizer,PZval,aptr]
			]
			[if,zscript:UseSamples,
				[VarSet,sptr,samped/2]
				[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
				[IColorSet,rcolor,gcolor,bcolor]
			]
			[if,zscript:UseSetDepth,
				[varSet,dchk,abs(zcolorcenter-PZval)]
				[if,dchk > maxZDelta,
					[VarSet,ddel,1]
				]
			]
		]

		[IPress,Stroke:DragRect]
		[CanvasClick,PHval1,PVval1,PHval2,PVval2]
		[IPress,Stroke:Dots]
		[note,Phval1,,1]
	,//else
		[RoutineCall,PixolLook,hcnt,vcnt,1,PZval,dummy,dummy,dummy]

		[loop,vSizer,
			[loop,hSizer,

				[RoutineCall,PixolLook,hcnt,vcnt,1,PZval,dummy,dummy,dummy]
				[if,zscript:PixolColor,
					[RoutineCall,PixolLook,hcnt,vcnt,0,chkcolor,rcolor,gcolor,bcolor]
					[if,zscript:usemask,
						[VarSet,tmp,abs(mskcolor-chkcolor)]
						[if,tmp < 1000,
							[IColorSet,rcolor,gcolor,bcolor]
							[CanvasClick,hcnt,vcnt,hcnt,vcnt]
						]
					,//else
						[IColorSet,rcolor,gcolor,bcolor]
						[CanvasClick,hcnt,vcnt,hcnt,vcnt]
					]
				,//else
					[if,zscript:UseZcolor,
						[RoutineCall,ZcolorCalc,hcnt,vcnt,PZval]
					]
					[if,zscript:UseShiftColor,
						[RoutineCall,Shiftcolor,hcnt,vcnt,PZval,aptr]
					]
					[if,zscript:UseSamples,
						[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
						[IColorSet,rcolor,gcolor,bcolor]
						[VarInc,sptr]
						[if,sptr=sampend,[VarSet,sptr,0]]
					]
					[if,zscript:UseSetDepth,
						[varSet,dchk,abs(zcolorcenter-PZval)]
						[if,dchk > maxZDelta,
							[VarSet,ddel,1]
							[LoopExit]
						]
					]

					[CanvasClick,hcnt,vcnt,hcnt,vcnt]
				]
				[VarSet,hcnt,hcnt+pensize]
				[if,hcnt>PHVal2,[loopexit]]
				[if,ddel>0,[LoopExit]]
			]
			[VarSet,hcnt,PHval1]
			[VarSet,vcnt,vcnt+pensize]
			[if,vcnt>PVval2,[loopexit]]
		]
	]
	[if,zscript:UseSetDepth,
		[if,ddel<>0,
			[note,maxZDelta,,-1]
			[note,"....Depth Achieved",,1]
		]
	]
]
[iButton,"RedoLast","Redo Last Pixolpaint",
	[VarSet,Sptr,0]
	[VarSet,hDelta,PHval2-PHval1]
	[VarSet,vDelta,PVval2-PVval1]
	[VarSet,hcnt,PHval1]
	[VarSet,vcnt,PVval1]
	[VarSet,ccolor,0]
	[VarSet,sptr,0]
	[VarSet,pensize,[Iget,Draw:DrawSize]]
	[VarSet,vsizer,INT(vdelta/pensize)+1]
	[VarSet,hsizer,INT(hdelta/pensize)+1]
	[VarSet,hsizer,hsizer*2]
	[VarSet,vsizer,vsizer*2]
	[VarSet,ddel,0]

	[if,zscript:usedrag,
		//Find Center
		[VarSet,vsizer,INT(vdelta/2)]
		[VarSet,hsizer,INT(hdelta/2)]
		[RoutineCall,PixolLook,hsizer,vsizer,1,PZval,dummy,dummy,dummy]

		[if,zscript:PixolColor,
			[RoutineCall,PixolLook,hsizer,vsizer,0,chkcolor,rcolor,gcolor,bcolor]
			[if,zscript:usemask,
				[VarSet,tmp,abs(mskcolor-chkcolor)]
				[if,tmp < 1000,
					[IColorSet,rcolor,gcolor,bcolor]
				]
			,//else
				[IColorSet,rcolor,gcolor,bcolor]
			]
		,//else
			[if,zscript:UseZcolor,
				[RoutineCall,ZcolorCalc,hsizer,vsizer,PZval]
			]
			[if,zscript:UseShiftColor,
				[RoutineCall,Shiftcolor,hsizer,vsizer,PZval,aptr]
			]
			[if,zscript:UseSamples,
				[VarSet,sptr,samped/2]
				[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
				[IColorSet,rcolor,gcolor,bcolor]
			]
			[if,zscript:UseSetDepth,
				[varSet,dchk,abs(zcolorcenter-PZval)]
				[if,dchk > maxZDelta,
					[VarSet,ddel,1]
				]
			]
		]

		[IPress,Stroke:DragRect]
		[CanvasClick,PHval1,PVval1,PHval2,PVval2]
		[IPress,Stroke:Dots]
		[note,Phval1,,1]
	,//else
		[RoutineCall,PixolLook,hcnt,vcnt,1,pzval,dummy,dummy,dummy]
	
		[loop,vSizer,
			[loop,hSizer,
				[RoutineCall,PixolLook,hcnt,vcnt,1,pzval,dummy,dummy,dummy]
				[if,zscript:PixolColor,
					[RoutineCall,PixolLook,hcnt,vcnt,0,chkcolor,rcolor,gcolor,bcolor]
					[if,zscript:usemask,
						[VarSet,tmp,abs(mskcolor-chkcolor)]
						[if,tmp < 1000,
							[IColorSet,rcolor,gcolor,bcolor]
							[CanvasClick,hcnt,vcnt,hcnt,vcnt]
						]
					,//else
						[IColorSet,rcolor,gcolor,bcolor]
						[CanvasClick,hcnt,vcnt,hcnt,vcnt]
					]
				,//else
					[if,zscript:UseZcolor,
						[RoutineCall,ZcolorCalc,hcnt,vcnt,pZval]
					]
					[if,zscript:UseShiftColor,
						[RoutineCall,Shiftcolor,hcnt,vcnt,pZval,aptr]
					]
					[if,zscript:UseSamples,
						[RoutineCall,ConvertComp,samps(sptr),rcolor,gcolor,bcolor]
						[IColorSet,rcolor,gcolor,bcolor]
						[VarInc,sptr]
						[if,sptr=sampend,[VarSet,sptr,0]]
					]
					[if,zscript:UseSetDepth,
						[varSet,dchk,abs(zcolorcenter-PZval)]
						[if,dchk > maxZDelta,
							[VarSet,ddel,1]
							[LoopExit]
						]
					]
					[CanvasClick,hcnt,vcnt,hcnt,vcnt]
				]
				[VarSet,hcnt,hcnt+pensize]
				[if,hcnt>phval2,[loopexit]]
				[if,ddel>0,[LoopExit]]
			]
			[VarSet,hcnt,pHval1]
			[VarSet,vcnt,vcnt+pensize]
			[if,vcnt>pvval2,[loopexit]]
		]
	]
	[if,zscript:UseSetDepth,
		[if,ddel<>0,
			[note,maxZDelta,,-1]
			[note,"...Depth Achieved",,1]
		]
	]
]
[varDef,theSStroke,(ZObjStrokeV02n57=H140VF0H140VF1H140VF2H141VF2H141VF3H141VF4H142VF4H142VF5H143VF5H144VF5H144VF6H145VF6H146VF6H147VF6H148VF6H149VF5H14AVF5H14BVF5H14CVF4H14DVF4H14EVF3H14EVF2H14FVF2H150VF1H151VF1H152VF1H153VF1H153VF2H154VF2H154VF3H155VF3H155VF4H155VF5H155VF6H156VF7H156VF8H156VF9H156VFAH156VFBH156VFCH156VFDH156VFEH156VFFH157VFFH158VFFH158VFEH159VFEH15AVFDH15BVFDH15CVFDH15CVFCH15DVFCH15EVFCH15EVFBH15FVFBH160VFAH160VFA)]
[VarDef,spikelen,1]
[iSlider,"Spikemult",1,.1,.0001,10,"Control the lenght of spikes ",[VarSet,spikelen,zscript:spikemult],0,[TextCalcWidth,SizeIncr4123]]

[iButton,"Spikes","Draw Spikes on Masked Color",
	[VarSet,Sptr,0]
	[RoutineCall,Mouselook,PHval1,PVval1,PHval2,PVval2,Clicked]
	[VarSet,hDelta,PHval2-PHval1]
	[VarSet,vDelta,PVval2-PVval1]
	[VarSet,hcnt,PHval1]
	[VarSet,vcnt,PVval1]
	[VarSet,ccolor,0]
	[VarSet,sptr,0]
	[VarSet,pensize,[Iget,Draw:DrawSize]]
	[VarSet,vsizer,INT(vdelta/pensize)+1]
	[VarSet,hsizer,INT(hdelta/pensize)+1]
	[VarSet,pensize,pensize*2]
	[VarSet,ddel,0]
	[RoutineCall,PixolLook,hcnt,vcnt,1,PZval,dummy,dummy,dummy]

	[loop,vSizer,
		[loop,hSizer,
			[RoutineCall,PixolLook,hcnt,vcnt,0,chkcolor,rcolor,gcolor,bcolor]
			[if,zscript:usemask,
				[VarSet,tmp,abs(mskcolor-chkcolor)]
			,//else
				[VarSet,tmp,0]
			]
			[if,tmp < 10,

				[varSet,theAngle,acos([pixolPick,6,hcnt,vcnt])]

				[if,[pixolPick,7,hcnt,vcnt] < 0,[varSet,theAngle,360-theAngle]]
				[varSet,theBothScale,1-abs([pixolPick,8,hcnt,vcnt])]
				[varSet,theBothScale,theBothScale*2]
				[varSet,theBothScale,theBothScale*spikelen]
	
				[varSet,theHScale,theBothScale]
				[varSet,theVScale,theBothScale]
				[varSet,theHOffset,hcnt- 320]
				[varSet,theVOffset,vcnt-240]
	
				[canvasStroke,theSStroke,0,theAngle,theHScale,theVScale,theHOffset,theVOffset]
			]
				[VarSet,hcnt,hcnt+pensize]
				[if,hcnt>phval2,[loopexit]]
				[if,ddel>0,[LoopExit]]
		]
			[VarSet,hcnt,pHval1]
			[VarSet,vcnt,vcnt+pensize]
			[if,vcnt>pvval2,[loopexit]]
	]
]

[PD]
//***************************************************
// Widget_Marker_Main - Include File
// Master Marker Include
//**************************************************************************
//********************Position Marks****************************************
//**************************************************************************
[varDef,MZ,0]
[varDef,MY,0]
[varDef,MZ,0]
[varDef,M1,0]
[varDef,M2,0]
[varDef,M3,0]
[FontSetColor,255,200,0]Position Marks..[FontSetColor,160,160,160]

[iSlider,"SelectMark",1,1,1,10,"Select Mark Index",
	[varSet,MarkIndex,zscript:SelectMark]
	[note,"Selected Mark...",,-1]
	[Note,MarkIndex,,1]
,0,[TextCalcWidth,SelectMark123]]
[iButton,"M+ ","Increment Mark",
	[VarInc,MarkIndex]
	[if, MarkIndex>10,[VarSet,MarkIndex,1]]
	[ISet,zscript:SelectMark,MarkIndex]
,0,0,.]
[iButton,"M- ","Decrement Mark",
	[VarDec,MarkIndex]
	[if, MarkIndex<1,[VarSet,MarkIndex,10]]
	[ISet,zscript:SelectMark,MarkIndex]
]
[iButton," Save ","Save Current Object Mark",
	[VarSet,MarkIndex,[IGet,zscript:SelectMark]]
	[note,"Saving Mark....",,-1]
	[note,MarkIndex,,1]
	[TransformGet,MarkX(MarkIndex),MarkY(MarkIndex),MarkZ(MarkIndex),MarkXS(MarkIndex),MarkYS(MarkIndex),MarkZS(MarkIndex),MarkXR(MarkIndex),MarkYR(MarkIndex),MarkZR(MarkIndex)]
	//Gather pertinent info about the object
	[VarSet,MarkTool(MarkIndex),[IGet,TOOL:iteminfo]]
	[VarSet,MarkMat(MarkIndex),[IGet,MATERIAL:iteminfo]]
	[VarSet,MarkR(MarkIndex),[IGet,Color:Redcomponent]]
	[VarSet,MarkG(MarkIndex),[IGet,Color:Greencomponent]]
	[VarSet,MarkB(MarkIndex),[IGet,Color:Bluecomponent]]
,,,CTRL+'m'
]
[iButton," Load ","Load Current Object Mark",
	[RoutineCall,LoadMark,MarkIndex]
,,,SHIFT+"l"
]
[RoutineDef,LoadMark,
	[VarDef,newchk,0]
	[VarDef,isold,0]
	[VarSet,newchk,0]	
	[if,[IGet,Transform:DrawPointer] == 1,[VarSet,isold,1],[VarSet,isold,0]]

	[ISet,zscript:SelectMark,imptr]
	[VarSet,MX,MarkX(imptr)]
	[VarSet,MY,MarkY(imptr)]
	[VarSet,MZ,MarkZ(imptr)]
	[VarSet,newchk,MX+MY+MZ]
	//check to see if a new marker
	//if user isn't holding an object make the original
	[if,isold == 1,
		[if,newchk <> 0,
			[ISet,Tool:ItemInfo,MarkTool(imptr)]
			[CanvasClick,MX,MY,MX+10,MY+10]
			[ISet,Transform:Move,1]
			[ISet,Material:ItemInfo,MarkMat(imptr)]
			[IColorSet,MarkR(MarkIndex),MarkG(imptr),MarkB(imptr)]
		]
	]
	[if,newchk <> 0,
		[if,isold == 1,
			[TransformSet,MX,MY,MZ,MarkXS(imptr),MarkYS(imptr),MarkZS(imptr),MarkXR(imptr),MarkYR(imptr),MarkZR(imptr)]
		,//else
			[TransformSet,MX,MY,MZ]
		]
	,//else
		[Note,"New Marker...",,-1]
		[note,MarkIndex,,1]
	]
//parameter
,imptr]
[iButton,"M1","Load Current Object Mark",
	[ISet,zscript:SelectMark,1]
,,,SHIFT+'1'
]
[iButton,"M2","Load Current Object Mark",
	[ISet,zscript:SelectMark,2]
,,,SHIFT+'2'
]
[iButton,"M3","Load Current Object Mark",
	[ISet,zscript:SelectMark,3]
,,,SHIFT+'3'
]
[iButton,"M4","Load Current Object Mark",
	[ISet,zscript:SelectMark,4]
,,,SHIFT+'4'
]
[iButton,"M5","Load Current Object Mark",
	[ISet,zscript:SelectMark,5]
,,,SHIFT+'5'
]
[iButton,"M6","Load Current Object Mark",
	[ISet,zscript:SelectMark,6]
,,,SHIFT+'6'
]
[iButton,"M7","Load Current Object Mark",
	[ISet,zscript:SelectMark,7]
,,,SHIFT+'7'
]
[iButton,"M8","Load Current Object Mark",
	[ISet,zscript:SelectMark,8]
,,,SHIFT+'8'
]
[iButton,"M9","Load Current Object Mark",
	[ISet,zscript:SelectMark,9]
,,,SHIFT+'9'
]
[iButton,"M10","Load Current Object Mark",
	[ISet,zscript:SelectMark,10]
,,,SHIFT+'0'
]
[PD]
//********************************************************
//******* SUBROUTINES ************************************
//********************************************************

//*********************************************
// Subroutine DepthCalc
// Calculate Size of current object using Zdepth Reference
//*********************************************
[RoutineDef,DepthCalc,
[VarDef,Zfactor,0]
[VarDef,ZMult,10]
[VarDef,TotalArea,0]
[VarDef,Delta]
	[VarSet,Delta,IcurrZ-RefZ]
	[VarSet,Zfactor,ZArea-Delta]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,ZMult,Zfactor/TotalArea]
	[VarAdd,ZMult,RefMult]
	//apply multiplier to result
	[VarSet,ZMult,ZMult*ZDmult]
	//set back to reference size
	[TransformSet,,,,RefXS,RefYS,RefZS]
	[TransformGet,Delta,Delta,Delta,IcurrXS,IcurrYS,IcurrZS]
	[VarMul,IcurrXS,ZMult]
	[VarMul,IcurrYS,ZMult]
	[VarMul,IcurrZS,ZMult]
	[TransformSet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
]
[PD]
//*********************************************
// Subroutine DistCalc
// Calculate Spacing Between 2 Zdepth Referenced Objects
//*********************************************
[RoutineDef,DistCalc,
[VarDef,Zfactor,0]
[VarDef,ZMult,10]
[VarDef,TotalArea,0]
	[VarSet,Delta,IcurrZ-RefZ]
	[VarSet,Zfactor,ZArea-Delta]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,ZMult,Zfactor/TotalArea]
	[VarAdd,ZMult,RefMult]
	//don't forget to add Z multiplier factor here
	[VarSet,Dmult,ZMult*ZDmult]
]
//*********************************************
// Subroutine GetDistance
// Calculate 2D Distance between 2 Points
//*********************************************
[VarDef,DistToMark,0]
[VarDef,DDistToMark,0]
[RoutineDef,GetDistance,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[VarSet,Xresult,Xtmp*Xtmp]
	[VarSet,Yresult,Ytmp*Ytmp]
	[VarSet,DistToMark,SQRT(Xresult+Yresult)]

//list of inputs
,Ox1,Ex1,Oy1,Ey1
]
//*********************************************
// Subroutine Get3DDistance
// Calculate 3D Distance between 2 Points
//*********************************************
[RoutineDef,Get3DDistance,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Ztmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,Zresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[VarSet,Ztmp,Oz1-Ez1]
	[VarSet,Xresult,Xtmp^^2]
	[VarSet,Yresult,Ytmp^^2]
	[VarSet,Zresult,Ztmp^^2]
	[VarSet,tmp,Xresult+Yresult+Zresult]
	[VarSet,DDistToMark,SQRT(tmp)]

//list of inputs
,Ox1,Ex1,Oy1,Ey1,Oz1,Ez1
]
//*********************************************
// Subroutine GetAngle
// Get 2D angle between 2 XY Points
//*********************************************
[RoutineDef,GetAngle,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[varSet,tmp,Xtmp/Ytmp]
	[VarSet,dangle,ATAN(tmp)]
	[if,Ytmp<0,
		[VarSet,dangle,dangle + 180]]
	//convert to user
	[VarSet,tmp,360-dangle+180]
	[VarSet,dangle,ABS(tmp)-360]
	[if,dangle<0,
		[VarSet,dangle,360-ABS(dangle)]]
	[VarAdd,Gxyangle,180]
	[if,dangle>360,[VarSet,dangle,dangle-360]]
//list of inputs
,Ox1,Ex1,Oy1,Ey1
]
//*********************************************
// Subroutine GetZAngle
// Get 2D angle between 2 XZ Points
//*********************************************
[RoutineDef,GetZAngle,
[VarDef,Xtmp,0]
[VarDef,Ztmp,0]
[VarDef,Xresult,0]
[VarDef,Zresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ztmp,Oz1-Ez1]
	[varSet,tmp,Xtmp/Ztmp]
	[VarSet,zdangle,ATAN(tmp)]
	[if,Ztmp<0,
		[VarSet,zdangle,zdangle + 180]]
	//convert to user
	[VarSet,tmp,360-zdangle+180]
	[VarSet,zdangle,ABS(tmp)-360]
	[if,zdangle<0,
		[VarSet,zdangle,360-ABS(zdangle)]]
	[VarAdd,zdangle,180]
	[if,zdangle>360,[VarSet,zdangle,zdangle-360]]
//list of inputs
,Ox1,Ex1,Oz1,Ez1
]
//*****************************
//SuperDooper Point script by Doctor Davey
//*****************************
[routineDef,PointFromTo,
[varSet,deltaX,lnewmX-lcurmX]
[varSet,deltaY,lnewmY-lcurmY]
[varSet,deltaZ,lnewmZ-lcurmZ]
[varSet,Rxz,sqrt((deltaX^^2)+(deltaZ^^2))]
[if,Rxz=0,
	[varSet,lXangle,(abs(deltaY)/deltaY)*-90]
	[varSet,lYangle,0]
, // else Rxz != 0
	[if,deltaZ=0,
		[varSet,deltaZ,-0.01]
	] // end if
	[varSet,lXangle,-atan(deltaY/Rxz)]
	[varSet,lYangle,-atan(deltaX/deltaZ)]
	[if,deltaZ > 0,[varSet,lYangle,-180+lYangle]]
] // end if
,lcurmX,lcurmY,lcurmZ,lnewmX,lnewmY,lnewmZ,lXangle,lYangle
] // end pointfromto routine


[RoutineDef,MakeLine,
	[RoutineCall,Get3DDistance,mlx,mrx,mly,mry,mlz,mrz]

	[VarSet,middlex,[Interpolate,.5,mlx,mrx]]
	[VarSet,middley,[Interpolate,.5,mly,mry]]
	[VarSet,middlez,[Interpolate,.5,mlz,mrz]]

	[TransformSet,middlex,middley,middlez,,,DDistToMark*.5]
	//let us now rotate it to the mark
	[routineCall,PointFromTo,middlex,middley,middlez,mrx,mry,mrz,Xangle,Yangle]
	[transformSet,,,,,,,Xangle,Yangle,mez]

,mlx,mrx,mly,mry,mlz,mrz,mez]

[RoutineDef,GetPosition,
	//rotate xyAxis and get x&ypt
	[VarSet,tmp,ang*2]
	[VarSet,tmp,180-tmp]
	[VarSet,ang1,ang+tmp]
	[if,ang1<0,
		[VarSet,ang1,360-ABS(ang1)]]
	//calc XY angle
	[VarSet,tmp,COS(ang1)]
	[VarSet,ypt,DIST1*tmp]
	[VarSet,tmp,SIN(ang1)]
	[VarSet,xpt,DIST1*tmp]

	//rotate xzAxis and get zpt
	[VarSet,tmp,zang*2]
	[VarSet,tmp,180-tmp]
	[VarSet,ang1,zang+tmp]
	[if,ang1<0,
		[VarSet,ang1,360-ABS(ang1)]]
	//calc XY angle
	[VarSet,tmp,SIN(ang1)]
	[VarSet,zpt,DIST1*tmp]

	,ang,zang,DIST1
]
//******************************
//Mouselook
// Routine to return Mouse Position values
//******************************
[RoutineDef,Mouselook,
	[loop,999999, // "endless" loop, user keeps clicking

		[loop,999999, // wait for mouse click
			[if,[mouseLbutton] = 1,
				[varSet,IHval1,[mouseHpos]]
				[varSet,IVval1,[mouseVpos]]
				[loopexit]
			] // end if
		] // end wait for mouse click loop

		[loop,999999, // now wait for mouse up
			[if,[mouseLbutton] = 0,
				[varSet,IHval2,[mouseHpos]]
				[varSet,IVval2,[mouseVpos]]
				[loopexit]
			] // end if
		] // end wait for mouse up loop

		[if,(IVval1 > 0), //(on the canvas)
			[if,(abs(IHval2-IHval1)<3) && (abs(IVval2-IVval1)<3),
				// single click
				[VarSet,IClicked,0]
			, // else = click + drag
				[VarSet,IClicked,1]
			] // end if click or drag
			[loopExit]
		] // end if (top button clicked/not clicked)
		[loop,99999, // ensure mouse button is up before continuing
			[if,[mouseLbutton] = 0,
				[loopExit]
			] // end if
		] // end ensure loop
	] // end "endless" loop
//parameters
,IHval1,IVval1,IHval2,IVval2,IClicked
]//end Mouselook
//******************************
//Pixollook
// Routine to return All Pixol values
//******************************
[RoutineDef,PixolLook,
	[if,itype = 0,	//return color information
		[VarSet,val1,[PixolPick,0,ihval,ivval]]
		[VarSet,val2,[PixolPick,2,ihval,ivval]]
		[VarSet,val3,[PixolPick,3,ihval,ivval]]
		[VarSet,val4,[PixolPick,4,ihval,ivval]]
	,//else
		[if,itype = 1,	//Return Zdepth and material
			[VarSet,val1,[PixolPick,1,ihval,ivval]]
			[VarSet,val2,[PixolPick,5,ihval,ivval]]
		,//else
			[if,itype = 2,	//Return Normals
				[VarSet,val1,[PixolPick,6,ihval,ivval]]
				[VarSet,val2,[PixolPick,7,ihval,ivval]]
				[VarSet,val3,[PixolPick,8,ihval,ivval]]
			]
		]
	]
//Parameters here
,ihval,ivval,itype,val1,val2,val3,val4
]
//=INT((D2-(A4*65536))/256)
//=D2-(A4*65536+B4*256)
//*************************
//ConvertComp - convert composite color to RGB
//*************************
[RoutineDef,ConvertComp,
	[VarSet,ired,INT(icomp/65536)]
	[VarSet,igreen,INT((icomp - (ired*65536))/256)]
	[VarSet,iblue,icomp - ((ired*65536)+(igreen*256))]
//parameters
,icomp,ired,igreen,iblue
]
//***********************
//ZcolorCalc
//Pick a color in the StartEnd gradient based on Z depth
//***********************
[RoutineDef,ZcolorCalc,
	[VarDef,tmp,0]
	[VarDef,tmp1,0]
	[VarDef,r,0]
	[VarDef,g,0]
	[VarDef,b,0]
	[VarDef,r1,0]
	[VarDef,g1,0]
	[VarDef,b1,0]
	[VarDef,r2,0]
	[VarDef,g2,0]
	[VarDef,b2,0]
	[VarDef,r3,0]
	[VarDef,g3,0]
	[VarDef,b3,0]
	[VarDef,totr,0]
	[VarDef,totg,0]
	[VarDef,totb,0]
	[VarSet,totr,0]
	[VarSet,totg,0]
	[VarSet,totb,0]
	[varSet,r,0]
	[VarSet,g,0]
	[VarSet,b,0]
	[varSet,r1,0]
	[VarSet,g1,0]
	[VarSet,b1,0]
	[varSet,r2,0]
	[VarSet,g2,0]
	[VarSet,b2,0]
	[VarSet,totr,0]
	[VarSet,totg,0]
	[VarSet,totb,0]
	[VarSet,tmp,0]
	[VarSet,tmp1,0]

	[if,deltr = 0,[VarSet,deltr,.0001]]
	[if,deltg = 0,[VarSet,deltg,.0001]]
	[if,deltb = 0,[VarSet,deltb,.0001]]
	//X Color
	[if,[IGet,zscript:C-X],
		
		//offset from center
		[VarSet,tmp1,XColorCenter - abs(daX)]
		[VarSet,tmp1,abs(tmp1)]
		//percent of total area
		[VarSet,tmp,(tmp1*100)/ZcolorDepth]
		[VarSet,tmp,tmp/100]
		
		//how many increments of total steps do they be?
		[VarSet,tmp1,CRadius*tmp]
		[VarSet,r1,tmp1*rincrm]
		[VarSet,g1,tmp1*gincrm]
		[VarSet,b1,tmp1*bincrm]
		
	]

	//Y color
	[if,[IGet,zscript:C-Y],
		//offset from center
		[VarSet,tmp1,YColorCenter - abs(daY)]
		[VarSet,tmp1,abs(tmp1)]

		//percent of total area
		[VarSet,tmp,(tmp1*100)/ZcolorDepth]
		[VarSet,tmp,tmp/100]

		//how many increments of total steps do they be?
		[VarSet,tmp1,CRadius*tmp]

		[VarSet,r2,tmp1*rincrm]
		[VarSet,g2,tmp1*gincrm]
		[VarSet,b2,tmp1*bincrm]
	]

	//Z color
	[if,[IGet,zscript:C-Z],
		
		//offset from center
		[VarSet,tmp1,ZcolorCenter - abs(daZ)]
		[VarSet,tmp1,abs(tmp1)]

		//percent of total area
		[VarSet,tmp,(tmp1*100)/ZcolorDepth]
		[VarSet,tmp,tmp/100]
		
		//how many increments of total steps do they be?
		[VarSet,tmp1,CRadius*tmp]
		
		[VarSet,r,tmp1*rincrm]
		[VarSet,g,tmp1*gincrm]
		[VarSet,b,tmp1*bincrm]
	]
	
	//add up increments
	//RED
	[VarSet,totr,r+r1+r2]
	[VarSet,tmp,totr/deltr]		//divide by Red Delta
	[VarSet,tmp1,tmp - INT(tmp)]	//Strip any whole
	[VarSet,tmp,tmp1*deltr]		//Circle thru span
	[VarSet,r,Sred(0)+tmp]		//Add to Start Color

	//GREEN
	[VarSet,totg,g+g1+g2]
	[VarSet,tmp,totg/deltg]
	[VarSet,tmp1,tmp - INT(tmp)]	//Strip any whole
	[VarSet,tmp,tmp1*deltg]
	[VarSet,g,Sgreen(0)+tmp]

	//BLUE
	[VarSet,totb,b+b1+b2]
	[VarSet,tmp,totb/deltb]
	[VarSet,tmp1,tmp - INT(tmp)]	//Strip any whole
	[VarSet,tmp,tmp1*deltb]
	[VarSet,b,Sblue(0)+tmp]



	[if,totr < 0,
		[if, r<Sred(0),
			[VarSet,r,Sred(1) + r]
		]
	,//else rincrm is positive
		[if,r>Sred(1),
			[VarSet,r,Sred(0) + (r-Sred(1))]
		]
		[if,r >= 255,
			[VarSet,r,Sred(0)]
		]
	]

	[if,totg < 0,
		[if, g<Sgreen(0),
			[VarSet,g,Sgreen(1) + g]
		]
	,//else gincrm is positive
		[if,g>Sgreen(1),
			[VarSet,g,Sgreen(0) + (g-Sgreen(1))]
		]
		[if,g >= 255,
			[VarSet,g,Sgreen(0)]
		]
	]

	[if,totb < 0,
		[if, b<Sblue(0),
			[VarSet,b,Sblue(1) + b]
		]
	,//else bincrm is positive
		[if,b>Sblue(1),
			[VarSet,b,Sblue(0) + (b-Sblue(1))]
		]
		[if,b >= 255,
			[VarSet,b,Sblue(0)]
		]
	]

	[IColorSet,r,g,b]
	[transformset,dax,day,daz+1]
	[transformset,dax,day,daz]
,daX,daY,daZ
]

//***********************
//ShiftColor
//Shift RGB Value from Start Color based on XYZ axis
//***********************
[RoutineDef,ShiftColor,
[VarDef,ax,0]
[VarDef,ay,0]
[VarDef,az,0]
[VarDef,stmp1,0]
[VarDef,stmp,0]
[VarDef,chk,0]
[VarDef,srcol,0]
[VarDef,sgcol,0]
[VarDef,sbcol,0]
	[VarSet,chk,0]
	[VarSet,stmp1,0]
	[VarSet,stmp,0]
	[VarSet,srcol,0]
	[VarSet,sgcol,0]
	[VarSet,sbcol,0]
	[if,iaptr=0,
		[VarSet,ax,iex]
		[VarSet,ay,iey]
		[VarSet,az,iez]
		[VarSet,chk,1]
	,//else
		[if,iaptr=1,
			[VarSet,ax,iey]
			[VarSet,ay,iez]
			[VarSet,az,iex]
			[VarSet,chk,2]
		,//else
			[VarSet,ax,iez]
			[VarSet,ay,iex]
			[VarSet,az,iey]
			[VarSet,chk,3]
		]
	]
	[if,chk=0,[Note,"Chk is zero",,1]]
	//RED
	//offset from center
	[if,[Iget,zscript:C-X],
		[VarSet,stmp1,XColorCenter - abs(ax)]
		[VarSet,stmp1,abs(stmp1)]
		//percent of total area
		[VarSet,stmp,(stmp1*100)/ZcolorDepth]
		[if,stmp = 0,
			[VarSet,srcol,Sred(0)]
		,				
			[VarSet,stmp,stmp/100]
			[If,stmp > 1,
				[VarSet,stmp,stmp - int(stmp)]
			]
			//how many increments of total steps do they be?
			[VarSet,stmp1,255*stmp]			//increment
			[VarSet,srcol,Int(srcol + stmp1)]		//new value
			[if,srcol > 255,
				[VarSet,srcol,srcol - 256]
			]
			[if,srcol < 0,
				[VarSet,srcol,srcol + 256]
			]
		]
		,//else
			[VarSet,srcol,Sred(0)]
		]
		//Green
		//offset from center
		[if,[Iget,zscript:C-Y],
			[VarSet,stmp1,YColorCenter - abs(ay)]
			[VarSet,stmp1,abs(stmp1)]
			//percent of total area
			[VarSet,stmp,(stmp1*100)/ZcolorDepth]
			[if,stmp = 0,
				[VarSet,sgcol,Sgreen(0)]
			,
				[VarSet,stmp,stmp/100]
				[If,stmp > 1,
					[VarSet,stmp,stmp - int(stmp)]
				]
				//how many increments of total steps do they be?
				[VarSet,stmp1,255*stmp]			//increment
				[VarSet,sgcol,INT(sgcol + stmp1)]		//new value
				[if,sgcol > 255,
					[VarSet,sgcol,sgcol - 256]
				]
				[if,sgcol < 0,
					[VarSet,sgcol,sgcol + 256]
				]
			]
		,//else
			[VarSet,sgcol,Sgreen(0)]
		]

		//Blue
		//offset from center
		[if,[Iget,zscript:C-Z],
			[VarSet,stmp1,YColorCenter - abs(az)]
			[VarSet,stmp1,abs(stmp1)]
			//percent of total area
			[VarSet,stmp,(stmp1*100)/ZcolorDepth]
			[if,stmp = 0,
				[VarSet,sbcol,Sblue(0)]
			,
				[VarSet,stmp,stmp/100]
				[If,stmp > 1,
					[VarSet,stmp,stmp - int(stmp)]
				]
				//how many increments of total steps do they be?
				[VarSet,stmp1,255*stmp]			//increment
				[VarSet,sbcol,INT(sbcol + stmp1)]		//new value
				[if,sbcol > 255,
					[VarSet,sbcol,sbcol-256]
				]
				[if,sbcol < 0,
					[VarSet,sbcol,sbcol+256]
				]
			]
		,//else
			[VarSet,sbcol,Sblue(0)]
		]
		[if,srcol > 255,
			[note,"red over 255",,1]
			[note,srcol,,1]
			[VarSet,srcol,srcol-256]
		]
		[if,srcol < 0,
			[note,"red less than 0",,1]
			[note,srcol,,1]
		]
		[if,sgcol > 255,
			[note,"green over 255",,1]
			[note,sgcol,,1]
			[VarSet,sgcol,sgcol-256]
		]
		[if,sgcol < 0,
			[note,"green less than 0",,1]
			[note,sgcol,,1]
		]
		[if,sbcol > 255,
			[note,"blue over 255",,1]
			[note,sbcol,,1]
			[VarSet,sbcol,sbcol-256]
		]
		[if,sbcol < 0,
			[note,"blue less than 0",,1]
			[note,sbcol,,1]
		]
		[Icolorset,srcol,sgcol,sbcol]
,iex,iey,iez,iaptr
]
//*************************
// Init Color Variables when changes are made
//*************************
[RoutineDef,initcolor,
	//get delta
	[Varset,deltr,sred(1)-sred(0)]
	[VarSet,deltg,sgreen(1)-sgreen(0)]
	[VarSet,deltb,sblue(1)-sblue(0)]
	[RoutineCall,FindMax,deltr,deltg,deltb,Cradius]
	//auto set colorstep
	[Iset,zscript:ColorStep,Cradius]	
	[VarSet,rincrm,(Sred(1)-Sred(0))/Cradius]
	[VarSet,gincrm,(Sgreen(1)-Sgreen(0))/Cradius]
	[VarSet,bincrm,(Sblue(1)-Sblue(0))/Cradius]
	[if,rincrm=0,[VarSet,rincrm,.00001]]
	[if,gincrm=0,[VarSet,gincrm,.00001]]
	[if,bincrm=0,[VarSet,bincrm,.00001]]
	[VarSet,Rcolor,Sred(0)]
	[VarSet,Gcolor,Sgreen(0)]
	[VarSet,Bcolor,Sblue(0)]
	//get global color for other routines
//	[RoutineCall,ConvertComp,Centercolor,Sred(0),Sgreen(0),Sblue(0)]
	[VarSet,CenterColor,[RGB,Sred(0),Sgreen(0),Sblue(0)]]
]
//*************************
//Find the max of three numbers
//*************************
[RoutineDef,FindMax,
	[varDef,ts1,0]
	[varDef,ts2,0]
	[VarSet,ismax,0]
	[VarSet,ts1,Max(abs(md1),abs(md2))]
	[VarSet,ts2,Max(abs(md1),abs(md3))]
	[VarSet,ismax,Max(ts1,ts2)]
	[VarSet,ismax,abs(ismax)]
,md1,md2,md3,ismax
]

